<?php

namespace App\Models;

use App\ModelFilters\QHSchoolSpecFilter;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Qh_SchoolSpec extends BaseModel
{
    protected $table = 'qh_school_specs';

    protected $guarded = [];

    public function school(): BelongsToMany
    {
        return $this->belongsToMany(Qh_School::class, 'qh_school_spec_real', 'schoolSpecId', 'schoolId');
    }

    public function modelFilter(): ?string
    {
        return $this->provideFilter(QHSchoolSpecFilter::class);
    }

    public function parent(): BelongsTo
    {
        return $this->belongsTo(Qh_SchoolSpec::class, 'parentId');
    }

    public function getProvinceAttribute($v) {
        return json_decode($v, JSON_UNESCAPED_UNICODE);
    }
}
